class SingletonBase(object):
    _instances = {}

    def __new__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super().__new__(cls, *args, **kwargs)
        return cls._instances[cls]


class Singleton(SingletonBase):
    def __init__(self):
        self.name = 'MySingletonClass'

    def print_name(self):
        print(self.name)

    def __str__(self):
        return self.name


if __name__ == '__main__':
    # 创建 MyClass 的两个实例
    instance1 = Singleton()
    instance2 = Singleton()

    # 通过两个实例调用 print_name 方法
    instance1.print_name()  # 输出: MySingletonClass
    instance2.print_name()  # 输出: MySingletonClass

    # 检查两个实例是否相同
    print(instance1 is instance2)  # 输出: True

'''
MySingletonClass
MySingletonClass
True
'''